//
//  ST_SweetLevelView.swift
//  btvideo
//
//  Created by mac on 2020/7/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftyJSON


class SweetLevelItemView: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        
        contentView.addSubview(icon_image_view)
        icon_image_view.snp.makeConstraints { (make) in
            make.width.equalTo(34)
            make.height.equalTo(34)
            make.left.equalToSuperview().offset(15)
            make.centerY.equalToSuperview()
        }
        
        
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.height.equalTo(22)
            make.left.equalToSuperview().offset(64)
            make.centerY.equalToSuperview().offset(-9)
        }
        
        contentView.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.height.equalTo(17)
            make.left.equalToSuperview().offset(64)
            make.top.equalTo(titleLabel.snp.bottom).offset(1)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor.init(hexString: "#ACB4C0")
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var icon_image_view:UIImageView = {
         let control = UIImageView()
          control.contentMode = .scaleAspectFill
          return control
      }()

    var model:ST_SweetValueLevelModel?{
        didSet{
            
            guard let m = model else { return  }
            
            
            icon_image_view.pin_setImage(from: m.image.compress_small_image(width: 34*3).url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            titleLabel.text = m.name
            
            content_label.text = m.detail
            
        }
    }
    
}


//MARK: - Model



class ST_SweetValueLevelModel : NSObject{

    var detail : String!
    var endIntimacy : Int!
    var image : String!
    var name : String!
    var startIntimacy : Int!

    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON){
        detail = json["detail"].stringValue
        endIntimacy = json["end_intimacy"].intValue
        image = json["image"].stringValue
        name = json["name"].stringValue
        startIntimacy = json["start_intimacy"].intValue
        super.init()
    }

}
